package model

import (
	"fmt"
	"log"
	"os"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"test_demo/config"
)

var DB *gorm.DB

func init() {
	newLogger := logger.New(
		log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
		logger.Config{},
	)
	configs:=new(config.Config)
	configData:=configs.GetConfig()
	var err error
	DB, err = gorm.Open(mysql.Open(configData.MysqlUrl), &gorm.Config{Logger: newLogger})
	if err != nil {
		fmt.Println("数据库连接失败")
	}
	sqlDb, _ := DB.DB()
	sqlDb.SetMaxIdleConns(200) //设置最大连接数
	sqlDb.SetMaxOpenConns(200) //设置最大的空闲连接数

}


